﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Net.Sockets;

namespace Sofire.DataComm.Net.Async
{
    /// <summary>
    /// 异步套接字抛出异常后发生的事件参数。
    /// </summary>
    public class AsyncSocketExceptionEventArgs : AsyncSocketEventArgs
    {
        private SocketOperation _Operation;
        /// <summary>
        /// 获取执行的异步套接字操作的类型。
        /// </summary>
        public SocketOperation Operation
        {
            get
            {
                return this._Operation;
            }
        }

        private Exception _Exception;
        /// <summary>
        /// 获取抛出的异常信息。
        /// </summary>
        public Exception Exception
        {
            get
            {
                return this._Exception;
            }
        }

        /// <summary>
        /// 获取一个值，表示当前抛出的异常，是否属于远程端断开的异常信息。
        /// </summary>
        public bool IsCloseException
        {
            get
            {
                return this._Exception == AsyncSocketBase.RemoteSocketCloseException;
            }
        }

        /// <summary>
        /// 初始化 <see cref="Sofire.DataComm.Net.Async.AsyncSocketExceptionEventArgs"/> 的新实例。
        /// </summary>
        /// <param name="asyncEventArgs">当前事件参数关联的 <see cref="System.Net.Sockets.SocketAsyncEventArgs"/>。</param>
        /// <param name="operation">异步套接字操作的类型。</param>
        /// <param name="exception">抛出的异常信息。</param>
        public AsyncSocketExceptionEventArgs(SocketAsyncEventArgs asyncEventArgs
            , SocketOperation operation
            , Exception exception)
            : base(asyncEventArgs)
        {
            this._Operation = operation;
            this._Exception = exception;
        }
    }
    /// <summary>
    /// 异步套接字抛出异常后发生的事件委托。
    /// </summary>
    /// <param name="sender">事件对象。</param>
    /// <param name="e">事件参数。</param>
    public delegate void AsyncSocketExceptionEventHandler(object sender, AsyncSocketExceptionEventArgs e);

}
